<?php

App::uses('AppController', 'Controller');

class SettingsController extends AppController {
    
    public $uses = array('Settings');
    
    public function index() {
        if (! empty($this->data)) {
            $data = array();
            foreach($this->data['Settings'] as $key=>$value) {
                $id = Set::extract('Settings.id', $this->Settings->findByKey($key));
                $data[] = array(
                    'Settings' => array(
                        'id'    => $id,
                        'value' => $value
                    )
                );
            }
            
            if ($this->Settings->saveAll($data)) {
                $this->setFlash('Podešavanja su uspešno sačuvana.', 'ok');
            } else {
                $this->setFlash('Greška pri čuvanju podešavanja.');
            }
        }
        
        $this->set('data', (object)$this->Settings->load());
    }
    
}
